package DAO;

import Entities.BookTagRefEntity;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

public class BookRefTagDao{
    static final String DB_URL = "jdbc:mysql://39.105.0.127:3306/booksite?characterEncoding=utf-8";
    static final String USER = "root";
    static final String PASS = "123456";
    private List<String> resList;


    public List<String> getRefTags(String bookID){
        resList = new ArrayList<>();
        Connection connection = null;
        Statement statement = null;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            connection = DriverManager.getConnection(DB_URL, USER, PASS);
            statement = connection.createStatement();
            String sql = "select ref_tag_title from book_tag_ref where ref_book_id = \'"+bookID+"\'order by count desc;";
            System.out.println(sql);
            ResultSet resultSet = statement.executeQuery(sql);
            while (resultSet.next())
            {
                String tag_title = resultSet.getString("ref_tag_title");
                resList.add(tag_title);
            }
            resultSet.close();
            statement.close();
            connection.close();
        }catch (Exception e){
            e.printStackTrace();
        }
        return resList;
    }
}
